var mask = null;
var refundid = null;
var xzauditstatus = null;
var bz = null;
var adultRecord = null;


$(function() { // 初始化内容
	mui.init();

	mask = mui.createMask(); //遮罩层

	login_user = JSON.parse(localStorage.getItem('loginUser'));
	refundid = sessionStorage.getItem('refundid')
	datetime_init();
	console.log("id======" + refundid)
	setTimeout(function() {
		loadRefundRecord();
	}, 300);


})



function loadRefundRecord() {

	var data = {};
	data['id'] = refundid;
	console.log("退款记录id====" + JSON.stringify(data));
	jQuery.ajax({
		headers: {
			'Authorization': login_user.token
		},
		type: "post",
		url: serverip + "fxgw/loadtksp",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层
		},
		success: function(res) {
			mask.close(); //显示遮罩层
			adultRecord = res.logList;
			console.log("退款记录====" + JSON.stringify(res));
			var onechannelname = res.newxlc_closing_record[0].onechannelname;
			var twochannelname = res.newxlc_closing_record[0].twochannelname;
			jQuery("#channal").val(onechannelname + "~" + twochannelname);
			loadForm(res.newxlc_closing_record[0]);
			var cashieraduitstatus = res.newxlc_closing_record[0].cashieraduitstatus;
			var zxjlauditstatus = res.newxlc_closing_record[0].zxjlauditstatus;
			console.log("zxjlauditstatus======" + zxjlauditstatus);
			if (zxjlauditstatus != "审核中") {
				jQuery("#submit").css("display", "none");
			}
			loadApp(res.adult_list)
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码' + code + "\n" + "错误信息:" + msg);
			console.log("错误信息====" + JSON.stringify(e));

		}
	});

}



function pass() {
	xzauditstatus = "分管领导审核通过";
	noPassText();
}

function noPass() {
	xzauditstatus = "分管领导审核不通过";
	noPassText();
}

function saveAuditResult() {
	var data = {};
	data['id'] = refundid;
	if (bz != null) {
		data['zxjlbz'] = bz;
	}
	data['zxjlauditstatus'] = xzauditstatus;
	console.log("审核成交记录上传====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "zjl/tksp",
		contentType: "application/json;charset=UTF-8",
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	   
		},
		success: function(data) {

			mask.close(); //显示遮罩层  	    	
			console.log(JSON.stringify(data));
			mui.alert('审核完成');

			setTimeout(function() {
				mui.back();
			}, 1000);
		},

		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("审核错误" + JSON.stringify(data));
		}
	});
}



function noPassText() {
	var btnArray = ['取消', '确定'];
	mui.prompt('请填写审核原因', '请填写审核原因', new Array('取消', '确定'), function(e) {
		if (e.index == 1) {
			//mui.toast(e.value);	    
			bz = e.value;
			saveAuditResult();

		} else {
			mui.toast('您取消了输入');
		}
	});
}

var app = new Vue({
	el: '#teachertable',
	data: {
		show: true,
		todos: []
	},
	methods: {
		selected: function(todo) {

		}
	}
});

function loadApp(data) {

	var arry = new Array();
	for (var i = 0; i < data.length; i++) {
		var d = data[i];
		var o = new Object();

		for (var x in d) {
			o[x] = d[x];
		}
		arry.push(o);
	}
	app.todos = arry;

}
function searchRecord(){
	console.log(JSON.stringify(adultRecord));
	window.sessionStorage.setItem("logMsg", JSON.stringify(adultRecord));
	window.location.href = "logList.html"
}